package com.sxdx.util;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import com.sxdx.entity.Orderinfo;

public class ExportExcel{
	private static List<Integer> weeks = new ArrayList<Integer>();
	private static List<Integer> types = new ArrayList<Integer>();
	static{
		weeks.add(2);
		weeks.add(3);
		weeks.add(4);
		weeks.add(5);
		weeks.add(6);
		
		types.add(1);
		types.add(2);
		types.add(3);
		types.add(4);
		
	}
	
	public static void expExcel(FileOutputStream out,String name,List<Orderinfo> orderinfolist){
		HSSFWorkbook wb = new HSSFWorkbook();
		HSSFSheet sheet = wb.createSheet(name);
		sheet.setDefaultRowHeight((short) 1500);
		sheet.setDefaultColumnWidth(30);
		HSSFCellStyle style = wb.createCellStyle();
		HSSFFont f = wb.createFont();
		f.setFontHeightInPoints((short)12);  
		f.setFontName("宋体"); 
		style.setFont(f);
		style.setWrapText(true);
		style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
		style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
		for(Orderinfo item : orderinfolist){
			Integer week = item.getODayofweek();
			Integer type = item.getOType();
			HSSFRow row = null;
			row = sheet.getRow(type);
			if(row == null){
				row = sheet.createRow(type);
			}
			HSSFCell cell = null;
			cell = row.getCell(week-1);
			if(cell == null){
				cell = row.createCell(week-1);
				cell.setCellStyle(style);
			}
			
			StringBuffer buf = new StringBuffer(cell.getStringCellValue());
			buf.append(item.toString());
			cell.setCellValue(buf.toString());
		}
		HSSFRow row0 =  sheet.createRow(0);
		HSSFCell cell00 = row0.createCell(0);
		cell00.setCellValue("节次");
		cell00.setCellStyle(style);
		HSSFCell cell01 = row0.createCell(1);
		cell01.setCellValue("礼拜一");
		cell01.setCellStyle(style);
		HSSFCell cell02 = row0.createCell(2);
		cell02.setCellValue("礼拜二");
		cell02.setCellStyle(style);
		HSSFCell cell03 = row0.createCell(3);
		cell03.setCellValue("礼拜三");
		cell03.setCellStyle(style);
		HSSFCell cell04 = row0.createCell(4);
		cell04.setCellValue("礼拜四");
		cell04.setCellStyle(style);
		HSSFCell cell05 = row0.createCell(5);
		cell05.setCellValue("礼拜五");
		cell05.setCellStyle(style);
		HSSFRow row1 =  sheet.getRow(1);
		row1.createCell(0).setCellValue("第一大节");
		HSSFRow row2 =  sheet.getRow(2);
		row2.createCell(0).setCellValue("第二大节");
		HSSFRow row3 =  sheet.getRow(3);
		row3.createCell(0).setCellValue("第三大节");
		HSSFRow row4 =  sheet.getRow(4);
		row4.createCell(0).setCellValue("第四大节");
		try {
			wb.write(out);
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}